package com.tunnel.common.config;

import com.tunnel.common.config.client.ClientConfig;
import com.tunnel.common.config.server.ServiceConfig;
import org.yaml.snakeyaml.Yaml;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class ServerParsConfig implements ParsConfig<ServiceConfig> {
    private static String configPath = "server-config.yml";
   public static ServiceConfig serviceConfig= new ServiceConfig();

    @Override
    public ClientConfig parse() {
        // 加载 YAML 文件
        InputStream inputStream = ClientParsConfig.class.getClassLoader().getResourceAsStream(configPath);
        // 创建 Yaml 对象
        Yaml yaml = new Yaml();
        // 解析 YAML 文件
        Map<String, HashMap<String, Object>> data = yaml.load(inputStream);
        String key = (String) data.get("server").get("key");
        Integer listenPort = (Integer) data.get("server").get("listenPort");
        Integer httpPort = (Integer) data.get("server").get("httpPort");
        Integer tcpPort = (Integer) (data.get("server").get("tcpPort"));
        Integer udpPort = (Integer) data.get("server").get("udpPort");
        serviceConfig.setKey(key);
        serviceConfig.setListenPort(listenPort);
        serviceConfig.setHttpPort(httpPort);
        serviceConfig.setTcpPort(tcpPort);
        serviceConfig.setUdpPort(udpPort);
        System.out.println("服务端配置解析完毕");
        return null;
    }
}
